<?php
/*
  Plugin Name: Abee Lajt
  Plugin URI: http://abee.pl
  Description: Plugin do stawiania stron z nakładką abee.pl
  Version: 0.2.1
  Author: http://abee.pl
  Author URI: http://abee.pl
  License: GPL
 */
?>
<?php
add_action('plugins_loaded', 'abee_admininit', 1);

function abee_admininit() {
    if (current_user_can('editor')) {

        $editor = get_role('editor');

        // Static cap mod for editor, depracieted in the near future
        $editor->add_cap('dash');
        $editor->add_cap('edit_menu');
        $editor->add_cap('edit_widgets');
        $editor->add_cap('edit_theme_options');
        $editor->add_cap('abee_settings');
        $editor->add_cap('abee_settingsMain');

        $editor->remove_cap('read');

        //Modern, dynami cap modiffication:
        $abee_editorMenu = get_option('abee_editorMenu');
        if ($abee_editorMenu != false) {
//            $abee_editorMenu = stripslashes( $abee_editorMenu );
            foreach ($abee_editorMenu as $value) {
                $editor->add_cap($value[1]);
            }
        }
        $editor->add_cap('abee_settingsMain');
    }

    if (basename($_SERVER[REQUEST_URI]) == 'index.php' || basename($_SERVER[REQUEST_URI]) == 'wp-admin') {
        if (current_user_can('editor')) {
            wp_redirect(get_admin_url() . 'admin.php?page=abee/dashboard.php');
            exit;
        } else {
            wp_redirect(get_admin_url() . 'edit.php?post_type=page');
            exit;
        }
    }
}

add_action('admin_menu', 'abee_adminmenu');

function abee_adminmenu() {
    global $menu;

    //only for administrators
    if (current_user_can('administrator')) {
        add_menu_page('Ustawienia', 'Abee Lajt', 'administrator', 'abee/options_page.php', '', plugins_url('favicon.ico', __FILE__));
        add_submenu_page('abee/options_page.php', 'Ustawienia Ogólne', 'Ustawienia Ogólne', 'administrator', 'abee/options_page.php');
        add_submenu_page('abee/options_page.php', 'Tło strony', 'Tło strony', 'administrator', 'abee/options.php');
        add_submenu_page('abee/options_page.php', 'Kokpit Edytora', 'Kokpit Edytora', 'administrator', 'abee/optionsDashboard.php');
        add_submenu_page('abee/options_page.php', 'Pomoc', 'Pomoc', 'administrator', 'abee/help.php');
    }

    add_menu_page('Panel administracyjny', 'Panel administracyjny', 'dash', 'abee/dashboard.php', '', '', 2);
    $menu[5] = $menu[20];
    unset($menu[20]);

    remove_menu_page('edit.php');
    remove_menu_page('link-manager.php');
    remove_menu_page('edit-comments.php');
    remove_submenu_page('plugins.php', 'plugin-editor.php');

    if (current_user_can('editor')) {
//        Special menu settings for editor, get from special option and added to menu through wp function
        $abee_editorMenu = get_option('abee_editorMenu');
        if ($abee_editorMenu != false) {
            $menu = array();
            foreach ($abee_editorMenu as $key => $value) {
                add_menu_page($value[0], $value[0], $value[1], $value[2], '', $value[6], $position = NULL);
            }
        }

//        add_menu_page('Edycja menu', 'Edycja menu', 'edit_menu', 'nav-menus.php', '', '', 20);
//        remove_menu_page('themes.php');
//
//        add_menu_page('Dodatki i ich rozmieszczenie', 'Dodatki i ich rozmieszczenie', 'edit_widgets', 'widgets.php', '', '', 30);
//
//        remove_menu_page('abee/options.php');
//
//        add_menu_page('Ustawienia ogólne', 'Ustawienia ogólne', 'abee_settingsMain', 'abee/options_page.php', '', '', 40);
//        add_menu_page('Tło strony', 'Tło strony', 'abee_settings', 'abee/options.php', '', '', 45);
//        remove_menu_page('tools.php');
    }
}

//setting login page

function abee_loginstyle() {
    ?>
    <style>
        body.login{
            background-image: url(<?= plugins_url('images/background.jpg', __FILE__) ?>);
        }
        .login h1 a {
            background: url(<?= plugins_url('images/logo.png', __FILE__) ?>) no-repeat top center;
        }
        a{text-shadow: none}
    </style>
    <?php
}

function abee_login() {
    abee_loginstyle();
}

add_action('login_head', 'abee_login');

include 'functions.php';

//add_action('admin_menu', 'abee_get_adminmenu');
function abee_get_adminmenu() {
    global $menu;
    print_r($menu);
    echo 'koniec';
}

//add_action('in_admin_header','abeeactiontest');
?>